package com.myproject.source;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;

public class LoadingActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setContentView(R.layout.loading);
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
				R.layout.title_bar);
		/** set time to splash out */
		final int welcomeScreenDisplay = 3000;

		/** create a thread to show splash up to splash time */
		new Handler().postDelayed(new Runnable() {
			public void run() {

				/* Create an intent that will start the main activity. */
				String KEY_USERID = "userid";
			
				Intent in = getIntent();
				String id = in.getStringExtra(KEY_USERID);
				Intent inOut = new Intent(getApplicationContext(),
						CityListActivity.class);
				inOut.putExtra(KEY_USERID, id);
				startActivity(inOut);
				startActivity(new Intent(LoadingActivity.this,
						CityListActivity.class));
				/* Finish splash activity so user cant go back to it. */
				LoadingActivity.this.finish();

				/*
				 * Apply our splash exit (fade out) and main entry (fade in)
				 * animation transitions.
				 */
			
			}
		}, welcomeScreenDisplay);
		// Thread welcomeThread = new Thread() {
		//
		// int wait = 0;
		//
		// @Override
		// public void run() {
		// try {
		// super.run();
		// /**
		// * use while to get the splash time. Use sleep() to increase
		// * the wait variable for every 100L.
		// */
		// overridePendingTransition(R.anim.mainfadein, R.anim.splashfadeout);
		// while (wait < welcomeScreenDisplay) {
		// sleep(100);
		// wait += 100;
		// }
		// } catch (Exception e) {
		// System.out.println("EXc=" + e);
		// } finally {
		// /**
		// * Called after splash times up. Do some action after splash
		// * times up. Here we moved to another main activity class
		// */
		// String KEY_USERID = "userid";
		// overridePendingTransition(R.anim.mainfadein, R.anim.splashfadeout);
		// Intent in = getIntent();
		// String id =in.getStringExtra(KEY_USERID);
		// Intent inOut = new Intent(getApplicationContext(),
		// CityListActivity.class);
		// inOut.putExtra(KEY_USERID,id);
		// startActivity(inOut);
		// // startActivity(new Intent(LoadingActivity.this,
		// // CityListActivity.class));
		//
		// finish();
		//
		// }
		// }
		// };
		// welcomeThread.start();

	}
}
